package com.example.validdemo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.validdemo.log.ApiLog;
import com.example.validdemo.model.Person;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;

/**
 * @author shenhan
 * @create 2020/1/19 13:11
 * @description
 */
@RestController
@RequestMapping("/api")
public class ValidController {
    @PostMapping("/getInfo")
    @ApiLog(apiName = "记录日志",apiCode = "129")
    public JSONObject getPersonInfo(@RequestBody @Valid Person person) {
        JSONObject rejson = new JSONObject();
        rejson.put("code", 0);
        rejson.put("msg", "ok");
        rejson.put("result", JSONObject.toJSONString(person));
        return rejson;
    }

    public static void main(String[] args) {
        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    }
}
